package bat.ke.qq.com.service.impl;

import bat.ke.qq.com.service.AccountService;
import bat.ke.qq.com.service.UserSerivce;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import sun.awt.AppContext;
import sun.awt.geom.AreaOp;

import javax.naming.Name;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 声明式事务
 */
@Service(value = "userService")
public class UserSerivceImpl implements UserSerivce {
    @Autowired
    AccountService accountService;

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Autowired
    UserSerivce userSerivce;

    @Override
    @Transactional()
    public void createUser(String name) throws Exception {
        // 插入user 记录
        jdbcTemplate.update("INSERT INTO `user` (name) VALUES(?)", name);
        // 调用 accountService 添加帐户
        accountService.addAccount(name, 100);
        // int i=1/0;
    }


}
